package com.xjc.business.controller.classadmin;

import com.xjc.business.entity.po.classadmin.ClassAdminLogoPo;
import com.xjc.business.entity.vo.classadmin.ClassAdminLoginVo;
import com.xjc.business.service.ClassAdminsService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 徐锦程
 * 时间:2025-01-30 22:03
 */
@RestController
@RequestMapping("/class_admin/user")
public class ClassUserController {

    @Autowired
    ClassAdminsService classAdminsService;

    /**
     * 登录
     * @param classAdminLogoPo 登录参数
     * @return 登录成功返回token，失败返回错误信息
     */
    @PostMapping("/login")
    public Result<ClassAdminLoginVo> doLogin(@RequestBody(required = false)ClassAdminLogoPo classAdminLogoPo){
        if(classAdminLogoPo == null || classAdminLogoPo.getUsername() == null || classAdminLogoPo.getPassword() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return classAdminsService.doLogin(classAdminLogoPo);
    }
}
